﻿{extend name="public:base" /}

{block name='css'}
<!--  富文本  -->
<link href="__ADMIN__/css/plugins/summernote/summernote-bs4.css" rel="stylesheet">
<!-- 富文本样式 -->
<style>
  .note-editor.note-frame .note-editing-area .note-editable {
    padding: 10px;
    overflow: auto;
    color: #000;
    word-wrap: break-word;
    background-color: #fff;
    height: 600px;
  }
</style>
{/block}

{block name="content"}


<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form method="post">
                        <div class="box-item">
                            <div class="form-group row"><label class="col-sm-1 col-form-label">标题</label>
                                <div class="col-sm-3">
                                    <input type="text" name="title" class="form-control" placeholder="请输入标题" value="{$info.title}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row"><label class="col-sm-1 col-form-label">所属分类</label>
                                <div class="col-sm-3">
                                    <select class="form-control m-b one_type_id" name="one_type_id">
                                        <option value="0">请选择一级分类</option>
                                        {volist name="type_list" id="vo"}
                                        <option value="{$vo.id}" {if ($vo['id'] == $info['one_type_id'])}selected{/if}>{$vo.name}</option>
                                        {/volist}
                                    </select>
                                </div>
                                <div class="col-sm-3">
                                    <select class="form-control m-b two_type_id" name="two_type_id">
                                        <option value="0">请选择二级分类</option>
                                        {volist name="two_type_list" id="vo"}
                                        <option value="{$vo.id}" {if ($vo['id'] == $info['two_type_id'])}selected{/if}>{$vo.name}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item file_block" style="display: none">
                            <div class="form-group row"><label class="col-sm-1 col-form-label">上传文件</label>

                                <div class="col-sm-3">
                                    <input type="file" id="upload_file" style="display: none">
                                    <input type="hidden" name="file_path" class="file_path" id="file" value="{$info['file_path']}"/>
                                    <input type="hidden" name="file_name" class="file_name" value="{$info['file_name']}"/>
                                    <div class="form-control" id="uploadFile" style="text-align: center; margin-bottom: 10px; cursor: pointer">{$info['file_name'] ? $info['file_name'] : '点击上传文件'}</div>
                                    <div class="form-control downloadUrl" style="text-align: center; display: none">文档下载链接：{:getHost()}/{$info['file_path']}</div>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row"><label class="col-sm-1 col-form-label">banner<br/>
                                <small class="text-navy"></small></label>

                                <div class="col-sm-3">
                                    <div class="i-checks">
                                        <label>
                                            <input type="radio" value="0" class="banner" name="is_banner" {if ($info['is_banner'] != 1)}checked{/if}>
                                            <i></i> 否 </label>
                                    </div>
                                    <div class="i-checks">
                                        <label>
                                            <input type="radio" value="1" class="banner" name="is_banner" {if ($info['is_banner'] == 1)}checked{/if}>
                                            <i></i> 是 </label>
                                    </div>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item img_block" style="display: none">
                            <div class="form-group row"><label class="col-sm-1 col-form-label">封面图</label>

                                <div class="col-sm-3">
                                    <input type="file" id="img_file" style="display: none">
                                    <input type="hidden" name="img" id="img" value="{$info['img']}"/>
                                    <img class="upload-file" src="{$info.img ? $info.img_path : '__ADMIN__/img/uploadBtn.png'}" id="uploadImg">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row"><label class="col-sm-1 col-form-label">排序</label>
                                <div class="col-sm-3">
                                    <input type="text" name="sort" class="form-control" placeholder="请输入排序" value="{$info.sort}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="row">
                                <label class="col-sm-1 col-form-label">简介</label>
                                <div class="col-lg-6">
                                    <div class="ibox ">
                                        <div class="ibox-content no-padding">
                                            <div id="summernote" style="height: 500px">
                                                {$info.content}
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>
                        </div>

                        <textarea id="summernote_val" name="content" style="display: none">{$info.content}</textarea>
                        <input type="hidden" name="id" value="{:input('id')}">

                        <div class="form-group row">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button type="button" class="btn btn-w-m btn-default back-page">返回</button>
                                <button type="button" class="btn btn-w-m btn-primary ajax-post">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"}
<!--  富文本  -->
<script src="__ADMIN__/js/plugins/summernote/summernote-bs4.js"></script>
<script>
    $(document).ready(function () {
        $('#summernote').summernote();

        var is_banner = "{$info.is_banner}";
        if(is_banner == 1){
            $('.img_block').show();
        }else{
            $('.img_block').hide();
        }

        var one_type_id = "{$info.one_type_id}";
        if(one_type_id == 55){
            $('.file_block').show();
            $('.downloadUrl').show();
        }

    });

    $('#summernote').on('summernote.change', function (we, contents, $editable) {
        $('#summernote_val').html(contents)
    });

    $('.one_type_id').change(function () {
        var one_type_id = $(this).val();

        if(one_type_id == 55){
            $('.file_block').show();
        }else{
            var url = "{:url('getTwoTypeList')}";

            $.post(url, {
                pid: one_type_id
            }, function (res) {
                var option = "<option value='0'>请选择二级分类</option>";
                if (res.result == 1) {
                    var list = res.data;
                    list.forEach(function (val) {
                        option += "<option value='" + val.id + "'>" + val.name + "</option>";
                    })
                }
                $('.two_type_id').html(option);
            }, 'json')
        }

    });

    $('.banner').change(function () {
        var is_banner = $(this).val();
        if (is_banner == 1) {
            $('.img_block').show();
        } else {
            $('.img_block').hide();
            $('#img').val(0);
            $('#uploadImg').attr('src', '__ADMIN__/img/uploadBtn.png');
        }
    });

    //文件上传
    $('#uploadFile').click(function (){
        $("#upload_file").trigger("click");
    })
    $("#upload_file").change(function (){
        var file = $(this)[0].files[0];
        var formData = new FormData();
        formData.append('file_obj', file);

        var url = "{:url('/admin/manage/uploadFile')}";
        $.ajax({
            url: url,
            type: "post",
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            success: function (e) {
                e = JSON.parse(e);

                if (e.result == 1) {
                    //上传成功
                    var file_name = e.data.upload_file_name;
                    var file_path = e.data.upload_file_path;

                    $('.file_path').val(file_path);
                    $('.file_name').val(file_name);
                    $('#uploadFile').html(file_name);

                    var downloadUrl = "{:getHost()}/" + file_path;
                    $('.downloadUrl').show().html('文档下载链接：' + downloadUrl);
                } else {
                    layer.msg(data.info);
                }
            }
        });
    })

    //图片上传
    $("#uploadImg").click(function () {
        $("#img_file").trigger("click");
    })
    $('#img_file').change(function () {
        var pic = $(this)[0].files[0];
        var formData = new FormData();
        var url = "{:url('/admin/common/uploadImg')}";
        formData.append('file_obj', pic);

        $.ajax({
            url: url,
            type: "post",
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            success: function (e) {
                e = JSON.parse(e);

                if (e.result == 1) {
                    //上传成功
                    var id = e.data.id;
                    var img = e.data.img;

                    $('#img').val(id);
                    $('#uploadImg').attr('src', img);
                } else {
                    layer.msg(data.info);
                }
            }
        });
    });
</script>

{/block}